//
//  UUWalletRefundDetailVC.m
//  UUCharterSupplier
//
//  Created by ZhangAo on 24/04/2018.
//  Copyright © 2018 UUCharter. All rights reserved.
//

#import "UUWalletRefundDetailVC.h"
#import "UUWalletManager.h"

@interface UUWalletRefundDetailVC () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UUWalletRefundDetailModel *record;
@property (nonatomic, weak) IBOutlet UITableView *tableView;
@property (nonatomic, copy) NSArray<NSDictionary *> *contents;

@end

@implementation UUWalletRefundDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    DKAssert(self.recordId != nil);
    
    self.title = @"退款详情";
    
    self.tableView.backgroundColor = COMMON_BACKGROUND_COLOR;
    
    ShowIndicator();
    WEAK_SELF();
    [GetWalletManager() asyncFetchRefundDetailWithRecordId:self.recordId
                                                moneyLogId:self.moneyLogId
                                             completeBlock:^(UUWalletRefundDetailModel *detail, NSError *error) {
                                                 HideIndicatorInView(weakSelf.view);
                                                 
                                                 if (error == nil) {
                                                     weakSelf.record = detail;
                                                     [weakSelf setupUI];
                                                 } else {
                                                     ShowTipsOnView(error.localizedDescription, weakSelf.view);
                                                 }
                                             }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupUI {
    self.contents = @[
                      @{@"title" : @"退款订单号", @"content" : self.record.orderSn},
                      @{@"title" : @"退款金额", @"content" : [self.record.refundMoney toCurrencyWithoutCurrencySymbol]},
                      @{@"title" : @"退款原因", @"content" : self.record.reason ?: @""},
                      @{@"title" : @"退款时间", @"content" : [self.record.createTime formatDateByFormatString:@"yyyy.MM.dd HH:mm:ss"]},
                      ];
    
    [self.tableView reloadData];
}

#pragma mark - UITableViewDelegate, UITableViewDataSource methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.contents.count;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    
    NSDictionary *content = self.contents[indexPath.row];
    
    UILabel *titleLabel = (UILabel *)[cell.contentView viewWithTag:1];
    titleLabel.textColor = COMMON_TEXT_LIGHT_COLOR;
    titleLabel.text = content[@"title"];
    
    UILabel *contentLabel = (UILabel *)[cell.contentView viewWithTag:2];
    contentLabel.textColor = COMMON_TEXT_BLACK_COLOR;
    contentLabel.text = content[@"content"];
    
    return cell;
}

@end
